using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace CXDB
{
	/// <summary>
	/// Strongly-typed collection for the CxUserLogin class.
	/// </summary>
    [Serializable]
	public partial class CxUserLoginCollection : ActiveList<CxUserLogin, CxUserLoginCollection>
	{	   
		public CxUserLoginCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>CxUserLoginCollection</returns>
		public CxUserLoginCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                CxUserLogin o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the CX_UserLogin table.
	/// </summary>
	[Serializable]
	public partial class CxUserLogin : ActiveRecord<CxUserLogin>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public CxUserLogin()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public CxUserLogin(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public CxUserLogin(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public CxUserLogin(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("CX_UserLogin", TableType.Table, DataService.GetInstance("CXDB"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarGuid = new TableSchema.TableColumn(schema);
				colvarGuid.ColumnName = "guid";
				colvarGuid.DataType = DbType.Guid;
				colvarGuid.MaxLength = 0;
				colvarGuid.AutoIncrement = false;
				colvarGuid.IsNullable = false;
				colvarGuid.IsPrimaryKey = true;
				colvarGuid.IsForeignKey = false;
				colvarGuid.IsReadOnly = false;
				colvarGuid.DefaultSetting = @"";
				colvarGuid.ForeignKeyTableName = "";
				schema.Columns.Add(colvarGuid);
				
				TableSchema.TableColumn colvarUid = new TableSchema.TableColumn(schema);
				colvarUid.ColumnName = "uid";
				colvarUid.DataType = DbType.Int32;
				colvarUid.MaxLength = 0;
				colvarUid.AutoIncrement = false;
				colvarUid.IsNullable = true;
				colvarUid.IsPrimaryKey = false;
				colvarUid.IsForeignKey = false;
				colvarUid.IsReadOnly = false;
				colvarUid.DefaultSetting = @"";
				colvarUid.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUid);
				
				TableSchema.TableColumn colvarUsername = new TableSchema.TableColumn(schema);
				colvarUsername.ColumnName = "username";
				colvarUsername.DataType = DbType.String;
				colvarUsername.MaxLength = 50;
				colvarUsername.AutoIncrement = false;
				colvarUsername.IsNullable = true;
				colvarUsername.IsPrimaryKey = false;
				colvarUsername.IsForeignKey = false;
				colvarUsername.IsReadOnly = false;
				colvarUsername.DefaultSetting = @"";
				colvarUsername.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUsername);
				
				TableSchema.TableColumn colvarIp = new TableSchema.TableColumn(schema);
				colvarIp.ColumnName = "ip";
				colvarIp.DataType = DbType.String;
				colvarIp.MaxLength = 100;
				colvarIp.AutoIncrement = false;
				colvarIp.IsNullable = true;
				colvarIp.IsPrimaryKey = false;
				colvarIp.IsForeignKey = false;
				colvarIp.IsReadOnly = false;
				colvarIp.DefaultSetting = @"";
				colvarIp.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIp);
				
				TableSchema.TableColumn colvarLoginOK = new TableSchema.TableColumn(schema);
				colvarLoginOK.ColumnName = "loginOK";
				colvarLoginOK.DataType = DbType.String;
				colvarLoginOK.MaxLength = 50;
				colvarLoginOK.AutoIncrement = false;
				colvarLoginOK.IsNullable = true;
				colvarLoginOK.IsPrimaryKey = false;
				colvarLoginOK.IsForeignKey = false;
				colvarLoginOK.IsReadOnly = false;
				colvarLoginOK.DefaultSetting = @"";
				colvarLoginOK.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLoginOK);
				
				TableSchema.TableColumn colvarIntime = new TableSchema.TableColumn(schema);
				colvarIntime.ColumnName = "intime";
				colvarIntime.DataType = DbType.DateTime;
				colvarIntime.MaxLength = 0;
				colvarIntime.AutoIncrement = false;
				colvarIntime.IsNullable = true;
				colvarIntime.IsPrimaryKey = false;
				colvarIntime.IsForeignKey = false;
				colvarIntime.IsReadOnly = false;
				
						colvarIntime.DefaultSetting = @"(getdate())";
				colvarIntime.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIntime);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["CXDB"].AddSchema("CX_UserLogin",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("Guid")]
		[Bindable(true)]
		public Guid Guid 
		{
			get { return GetColumnValue<Guid>(Columns.Guid); }
			set { SetColumnValue(Columns.Guid, value); }
		}
		  
		[XmlAttribute("Uid")]
		[Bindable(true)]
		public int? Uid 
		{
			get { return GetColumnValue<int?>(Columns.Uid); }
			set { SetColumnValue(Columns.Uid, value); }
		}
		  
		[XmlAttribute("Username")]
		[Bindable(true)]
		public string Username 
		{
			get { return GetColumnValue<string>(Columns.Username); }
			set { SetColumnValue(Columns.Username, value); }
		}
		  
		[XmlAttribute("Ip")]
		[Bindable(true)]
		public string Ip 
		{
			get { return GetColumnValue<string>(Columns.Ip); }
			set { SetColumnValue(Columns.Ip, value); }
		}
		  
		[XmlAttribute("LoginOK")]
		[Bindable(true)]
		public string LoginOK 
		{
			get { return GetColumnValue<string>(Columns.LoginOK); }
			set { SetColumnValue(Columns.LoginOK, value); }
		}
		  
		[XmlAttribute("Intime")]
		[Bindable(true)]
		public DateTime? Intime 
		{
			get { return GetColumnValue<DateTime?>(Columns.Intime); }
			set { SetColumnValue(Columns.Intime, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(Guid varGuid,int? varUid,string varUsername,string varIp,string varLoginOK,DateTime? varIntime)
		{
			CxUserLogin item = new CxUserLogin();
			
			item.Guid = varGuid;
			
			item.Uid = varUid;
			
			item.Username = varUsername;
			
			item.Ip = varIp;
			
			item.LoginOK = varLoginOK;
			
			item.Intime = varIntime;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(Guid varGuid,int? varUid,string varUsername,string varIp,string varLoginOK,DateTime? varIntime)
		{
			CxUserLogin item = new CxUserLogin();
			
				item.Guid = varGuid;
			
				item.Uid = varUid;
			
				item.Username = varUsername;
			
				item.Ip = varIp;
			
				item.LoginOK = varLoginOK;
			
				item.Intime = varIntime;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn GuidColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn UidColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn UsernameColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn IpColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn LoginOKColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn IntimeColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string Guid = @"guid";
			 public static string Uid = @"uid";
			 public static string Username = @"username";
			 public static string Ip = @"ip";
			 public static string LoginOK = @"loginOK";
			 public static string Intime = @"intime";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
